package com.shhm.business.controller;

import com.shhm.business.service.AnnouncementService;
import com.shhm.common.annotations.OperateLog;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.security.SecurityUser;
import com.shhm.common.entity.common.AnnouncementEntity;
import jakarta.annotation.Resource;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/12 下午8:36
 */
@RestController
//@RequestMapping("/admin")
public class AnnouncementController {
    @Resource
    private AnnouncementService announcementService;

    @GetMapping("/admin/announcement")
    public AjaxResultPlus productTypePage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage
    ){
        return announcementService.productTypeList(pageNum, pageSize, isPage);
    }

    @PostMapping("/admin/announcement/search")
    public AjaxResultPlus pageSearchList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody AnnouncementEntity entity
    ){
        return announcementService.pageSearchList(pageNum,pageSize,entity);
    }

    @PostMapping("/admin/announcement")
    @OperateLog(module="公告类型管理",type = "POST",desc = "添加系统公告类型信息")
    public AjaxResultPlus add(@RequestBody AnnouncementEntity entity){
        SecurityUser user = (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        entity.setCreateBy(user.getUserId());
        entity.createLocalDateTime();
        return announcementService.add(entity);
    }

    @PutMapping("/admin/announcement")
    @OperateLog(module="公告类型管理",type = "PUT",desc = "修改系统公告类型信息")
    public AjaxResultPlus update(@RequestBody AnnouncementEntity entity){
        return announcementService.update(entity);
    }

    @DeleteMapping("/admin/announcement")
    @OperateLog(module="公告类型管理",type = "DELETE",desc = "删除系统公告类型")
    public AjaxResultPlus delete(@RequestBody RequestList ids){
        return announcementService.delete(ids);
    }
}
